<?php

class City_DanhmuctinhthanhController extends Zend_Controller_Action {

	public function init() {
		$this->params = $this->getRequest()->getParams();
		System_Template::using("getit", "Admin");
		$this->model = new City_Model_Danhmuctinhthanh();
		parent::init();
	}

	public function indexAction() {
		$this->view->maintitle = "Danh sách tỉnh thành";
		$model = new City_Model_Danhmuctinhthanh();
		$name = $this->_request->getParam("name");
		$this->view->name = $name;
		$parameter = array('name' => $name);
		$count = $model->count($parameter);
		$paging = common::pagingAuto($count);
		$data = $model->SelectAll($parameter, $paging[0], $paging[1]);
		$this->view->data = $data;
		// common::showButton('delete');
		// common::showButton('add');
	}

	public function inputAction() {
		// common::showButton('save');
		// common::showButton('back');
		$this->qldscty = new City_Model_Danhmuctinhthanh();
		$id = $this->_getParam("id");
		$this->view->flag = 0;
		if ($id == 0) {
			$this->view->maintitle = "Thêm tỉnh thành vào danh sách";
		} else {
			$this->view->maintitle = "Cập nhật thông tin tỉnh thành";
			$data = $this->qldscty->FindById($id);
			$this->view->data = $data;
			$this->view->id = $id;
			$this->view->flag = 1;
		}
	}
	public function saveAction() {
		$this->model->AddNewTower($this->params);
		$this->_redirect('/city/danhmuctinhthanh/index');
	}
	public function deleteAction() {
		$params = $this->getRequest()->getParams();
		$db = Zend_Db_Table::getDefaultAdapter();
		$ids = $params["DEL"];
		for ($i = 0; $i < count($ids); $i++) {
			$this->model->DeleteTower($ids[$i]);
		}
		$this->_redirect("/city/danhmuctinhthanh/index");
	}

}

